package ms.maplestory.boot.client.character.quest.progress;

import lombok.Getter;
import lombok.Setter;
import ms.maplestory.boot.client.character.Char;
import ms.maplestory.boot.loaders.DatSerializable;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

@Getter
@Setter
@Entity
@DiscriminatorValue("item")
public class QuestProgressItemRequirement extends QuestProgressRequirement {

    @Column(name = "unitId")
    private int itemId;
    @Column(name = "requiredCount")
    private int requiredCount;

    @Override
    public boolean isComplete(Char chr) {
        return false;
    }

    @Override
    public QuestProgressRequirement deepCopy() {
        QuestProgressItemRequirement questProgressItemRequirement = new QuestProgressItemRequirement();
        questProgressItemRequirement.setItemId(getItemId());
        questProgressItemRequirement.setRequiredCount(getRequiredCount());
        questProgressItemRequirement.setOrder(getOrder());
        return questProgressItemRequirement;
    }

    @Override
    public void write(DataOutputStream dos) throws IOException {
        dos.writeInt(getItemId());
        dos.writeInt(getRequiredCount());
        dos.writeInt(getOrder());
    }

    @Override
    public DatSerializable load(DataInputStream dis) throws IOException {
        QuestProgressItemRequirement questProgressItemRequirement = new QuestProgressItemRequirement();
        questProgressItemRequirement.setItemId(dis.readInt());
        questProgressItemRequirement.setRequiredCount(dis.readInt());
        questProgressItemRequirement.setOrder(dis.readInt());
        return questProgressItemRequirement;
    }

}
